import neurones.Reseau;
import dauphine.util.*;
public class Othello{
    public static void main(String[] args){
        Console.start();
        Runtime info=Runtime.getRuntime();
        long baseMemory;
        info.gc();
        baseMemory=info.freeMemory();
        Board board=new Board();
        ComputerPlayer cp=new ComputerPlayer(Board.BLACK, board, 6 , null, new Reseau(args[1]));
        info.gc();
        double usedMemory=(double)(info.freeMemory()-baseMemory)/(1<<20);
        System.out.println("Memoire requise en Mo : " + usedMemory);
        boolean human=true;
        int pieces=0;
        System.out.println(board);
        while(!board.gameOver()){
            if(!board.canMove(Board.WHITE))
                human=false;
            if(human){
                System.out.println("Entrer votre coup : ");
                String s=Console.readString();
                int position=Board.encodePosition(s);
                System.out.println("position = " + position);
                System.out.println("position = " + Board.decodePosition(position));
                int move=board.legal(Board.WHITE,position);
                if(move!=-1){
                    board.doMove(Board.WHITE,move);
                    human=!human;
                }
            } else {
                cp.scannedPositions=0;
                cp.transpo=0;
                
                int bestMove=cp.getMove();
                System.out.println("Score obtenu: " + cp.bestScore + " positions explor�es : " + cp.scannedPositions);
                System.out.println("Transpositions : " + cp.transpo);
                System.out.println("% tranpo : " + ((double)cp.transpo)/cp.scannedPositions);
                System.out.println("#collision : "  + cp.collision);
                int position=bestMove>>Board.moveShift[Board.DIRECTIONS] & 127;
                
                if(board.legal(Board.BLACK,position)!=-1){
                    board.doMove(Board.BLACK,cp.bestMove);
                    System.out.println("Coup ordi : " + Board.decodePosition(position));
                    System.out.println("Profondeur : " + cp.myDepth + " game over : " +cp.go);
                }else{
                    System.out.println("Ordi passe");
                }
                human=!human;
            }
            System.out.println(board);
            pieces ++;
        }
        System.out.println("Partie terminee");
    }
}
